$(function () {

	/***********代码高亮**************/
	$('.lgl-art-box pre').each(function () {
		$(this).addClass("line-numbers");
		Prism.highlightElement($(this).find("code").get(0));
	});

	/***********分页**************/
	$('.lgl-pagination-box').each(function () {
		LGL.initPagination($(this));
	});

		/***********菜单选中**************/
		var currentUrl = document.location.href;
		var urlPart = currentUrl.replace(/^.*?\/\/[^\/]+?\//, '/');
		var selectedFlag = false;
		var isPageFlag = false;
		$('#top-nav-menu li').each(function () {
			var urlAttr = $(this).attr('url');
			if (urlAttr && urlAttr.length > 2 && urlPart.startsWith(urlAttr)){
				if(urlPart.startsWith("/posts/") && urlPart!="/posts/"){
					isPageFlag = true;
				}else{
					$(this).addClass('selected');
					selectedFlag = true;
				}
				return false;
			}
		});
		
		if(!isPageFlag && !selectedFlag){
			$("#top-nav-menu li[url='/']").addClass('selected');
		}

		/***********跳到顶部**********/
		$("#jump-top-btn").on("click",function () {
			$("html,body").animate({scrollTop: 0,},300);
		});
		$(window).on("scroll",function () {
			if ($(window).scrollTop() > 100) {
				$("#jump-top-btn").css("display", "block");
			} else {
				$("#jump-top-btn").css("display", "none");
			}
		});

		/**********小屏幕菜单处理***********/
		$("#mobile-menu-btn").on("click",function(){
			$("#top-nav-menu").toggleClass("active");
		});

		$(document).on("click",function(e){
			if(!$(e.target).hasClass("menu-switch")){
				$("#top-nav-menu").removeClass("active");
			}
		});
    /**************初使化搜索功能**************/
		LGL.initSearchFunc();

});


